<?php
/**
 * 基础Action，所有的Action都继承自此Action，目的是方便以后做项目的Action扩展
 * @author SongKejing 2012.12.26
 * @todo 扩展公用方法
 */
class BaseAction extends Action{
	
	public function _initialize(){
		$this->resetSessionID();
//		$this->checkUserLogin();
		$this->checkUserPower();
	}
	
	/**
	 * 检查用户是否登录，如果没有登录则跳转到登录页面
	 */
	public function checkUserLogin(){
		if(!isset($_SESSION['uid']) || empty($_SESSION['uid'])){
			$this->assign('errorMsg', '登录已失效，请重新登录！');
			$this->display('Public:login');
		}
	}
	
	/**
	 * 检查用户权限
	 */
	public function checkUserPower(){
		log::write('REQUEST_URI:'.$_SERVER['REQUEST_URI']);
		log::write('PATH_INFO:'.$_SERVER['PATH_INFO']);
//		$powers = json_decode($_SESSION['powers'], true);
	}
	
	/**
	 * 重置session_id
	 */
	public function resetSessionID(){
		log::write('resetSessionID:'.print_r($_POST, true));
		if(isset($_POST['rpc_session_id'])){
			if(Session::id() != $_POST['rpc_session_id']){				
				Session::id($_POST['rpc_session_id']);
			}
		}
		//保存session_id到session用于输出
		$_SESSION['rpc_session_id'] = Session::id();
	}
	
}
?>